<template>
	<div class="flex-page-wrapper" @click="closeMenu">
		<!-- <live-player
	    src="https://pull.alive.alipay.com.cn/livecdn/A202508134306787001000099_web_web264middle.m3u8?auth_key=1819865058-0-0-a3e463f8561197a50d2999dc2a3bbd2f"
	    autoplay
	  		mode="live"
	    style="width: 360px; height: 300px; padding: 20px 0;"
	  /> -->
		<uni-nav-bar statusBar color="" backgroundColor="#7350f5" title="" :height="0" v-if="!showWebcome">
		</uni-nav-bar>
		<div class="welcome" :style="{ opacity: welComeOpaciy }" v-if="showWebcome">
		</div>
		<div class="home page-flex" v-else>
			<top v-if="showVideo"></top>
			<updates :list="trendsData"></updates>
			<highlights></highlights>
			<sponsor></sponsor>
			<wsh-footer></wsh-footer>
		</div>
		<login ref="login" v-if="showLogin && !showWebcome" @success="loginSuccess"></login>
		<foot-wap :value="0" v-if="!showWebcome"></foot-wap>
		<web-tips v-if="showTips"></web-tips>
		<!-- <button style="position: fixed; left: 100px; top: 300px;" @click="linkFn">模拟碰一碰</button> -->
	</div>
</template>
<script>
	import top from './components/top.vue'
	import updates from './components/updates.vue'
	import highlights from './components/highlights.vue'
	import sponsor from './components/sponsor.vue'
	import login from '../login'
	import protal from "@/api/protal"
	import JSEncrypt from '../../static/jsencrypt.min.js'

	export default {
		onShareTimeline(res) {
			return {
				title: 'Inclusion外滩大会',
				desc: 'Inclusion外滩大会是在上海举办的全球高级别金融科技和前沿科技大会，致力于搭建全球科技、金融和产业间的高规格开放对话平台，展现AI时代全球科技创新趋势，助力上海打造国际金融中心和科技创新中心。',
				path: '/pages/index/index',
				imageUrl: 'https://static.inclusionconf.com/static/images/chat/foot-icon-new2.png',
				success: () => {}
			}
		},
		onShareAppMessage(res) {
			return {
				title: 'Inclusion外滩大会',
				desc: 'Inclusion外滩大会是在上海举办的全球高级别金融科技和前沿科技大会，致力于搭建全球科技、金融和产业间的高规格开放对话平台，展现AI时代全球科技创新趋势，助力上海打造国际金融中心和科技创新中心。',
				path: '/pages/index/index',
				imageUrl: 'https://static.inclusionconf.com/static/images/chat/foot-icon-new2.png',
				success: () => {}
			}
		},
		components: {
			top,
			updates,
			highlights,
			sponsor,
			login,
			// xingcheng,

		},
		data() {
			return {
				trendsData: [],
				showLogin: !uni.getStorageSync('token'), // 打开助手 登录
				showXingcheng: !!uni.getStorageSync('token'), // 打开助手 行程
				showWebcome: false,
				welComeOpaciy: 1,
				showVideo: true,
				showMenu: false,
				showTips: false,
				vid: ''
			}
		},
		onLoad(options) {
			// #ifdef MP-ALIPAY
			console.log(options, '个人中心参数')
			if (options.verifyEventInfo) {
				const query = JSON.parse(options.query)
				const verifyEventInfo = JSON.parse(options.verifyEventInfo)
				this.vid = verifyEventInfo.vid
				console.log(this.vid, '打印一下SN vid')
			}
			// #endif
		},
		async onShow() {
			this.showTips = true
			if (this.vid) {
				await protal.vidLogin({
					vid: this.getCrypt()
				}).then(res => {
					if (res.code === '0000') {
						uni.setStorageSync('token', res.data.token)
					}
				})
			}
			this.showLogin = !uni.getStorageSync('token')
			this.showWebcome = !!uni.getStorageSync('showWebcome')
		},
		onHide() {
			this.showTips = false
		},
		computed: {
			refreshState() {
				return this.$store.state.refreshState
			},
			showSub() {
				return this.$store.state.showSub
			}
		},
		watch: {
			refreshState() {
				this.showLogin = !uni.getStorageSync('token')
				this.showWebcome = !!uni.getStorageSync('showWebcome')
			},
			showWebcome: {
				handler(v) {
					if (v) {
						setTimeout(() => {
							this.welComeOpaciy = 0
						}, 100)
						setTimeout(() => {
							this.showWebcome = false
							uni.setStorageSync('showWebcome', '')
						}, 3000)
					}
				},
				immediate: true
			}
		},
		methods: {
			getCrypt() {
				var str = this.vid;
				// 公钥
				var publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCCyuMRsaJXsRs/IhUBsQeVU87qpa/ndLmSE0zkEq48K7ADmk/5jlwpP/FLXNn6xCexGOp1MOeSEmOEa6OrLrxS3UI+U8e/dJNoj+QAe2fQPMi73mZQv497P0Q2WaVeW6PSkuaTRSMDJCN2S8c/y+Y+5VmaX6uNOA48uSI/WpXAzwIDAQAB";
				// 加密
				var encrypt = new JSEncrypt();
				encrypt.setPublicKey(publicKey);
				var encryptStr = encrypt.encrypt(str);
				return encryptStr
			},
			linkFn() {
				const query = {
					SN: "LSN5DA0024B4GA3JAAD",
					bbb: "222"
				}
				const verifyEventInfo = {
					"timeUuid": "AA2025B01W5t",
					vid: "64d57121844ff0f98fa3aba73713f05f"
				}
				uni.navigateTo({
					url: `/pages/index/index?query=${ JSON.stringify(query) }&verifyEventInfo=${ JSON.stringify(verifyEventInfo) }`
				})
			},
			trendsList() {
				protal.trendsList({
					pageNum: 1,
					pageSize: 3
				}).then(res => {
					this.trendsData = res.data
				})
			},
			loginSuccess() { // 登录成功打开行程
				// this.showLogin = false
				// this.showXingcheng = true
				// this.$nextTick(() => {
				//   this.$refs.xingcheng.show = true
				//   if (this.$refs.xingcheng.times && this.$refs.xingcheng.times.length) {
				//     this.$refs.xingcheng.queryTripList()
				//   }
				// })
			},
			openLogin() { // 直接打开登录
				this.showLogin = true
				this.showXingcheng = false
				this.$nextTick(() => {
					this.$refs.login.show = true
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.home {
		width: 100%;
		overflow-x: hidden;
		margin-top: -1px;
	}

	.welcome {
		position: fixed;
		left: 0;
		top: 0;
		right: 0;
		height: 100vh;
		z-index: 99999;
		background: url(https://static.inclusionconf.com/static/images/new/welcome-t1.png) no-repeat;
		background-size: 100% auto;
		background-color: #784DFF;
		transition: 6s;
	}
</style>